import { crypto } from "@ohos/node-polyfill";
import { join } from "./path";

import { getHomeDir } from "./getHomeDir";
import { fileIo as fs } from "@kit.CoreFileKit";

/**
 * Returns the filepath of the file where SSO token is stored.
 * @internal
 */
export const getSSOTokenFilepath = (id: string) => {
  const hasher = crypto.createHash("sha1");
  const cacheName = hasher.update(id).digest("hex");
  const folder = join(getHomeDir(), ".aws", "sso", "cache")
  if (!fs.accessSync(folder)) {
    fs.mkdirSync(folder, true)
  }
  return join(folder, `${cacheName}.json`);
};
